package com.iplay.service.notification.type.order.type;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import com.iplay.component.im.OutgoingMessage;
import com.iplay.dto.ApiResponseMessage;
import com.iplay.service.notification.type.order.OrderMessage;
import com.iplay.service.notification.type.order.OrderMessageEntity;
import com.iplay.service.notification.type.order.OrderOutgoingMessage;
import com.iplay.service.order.RoleInOrder;

public class OrderCashbackMessage extends OrderMessageType {

	public OrderCashbackMessage(OrderMessageEntity entity) {
		super(entity);
	}

	@Override
	public List<OutgoingMessage> getOutgoingMessage() {
		OrderMessageEntity entity = this.getEntity();
		List<OutgoingMessage> messages = new LinkedList<>();
		Set<String> receivers = new HashSet<>();
		messages.add(new OrderOutgoingMessage(entity.getCustomer(), new OrderMessage(entity.getOrderId(),
				RoleInOrder.CUSTOMER, entity.getOrderStatusCategory(),  String.format(ApiResponseMessage.ORDER_CASHBACK_FOR_CUSTOMER, entity.getHotel()))));
		receivers.add(entity.getCustomer());
		if(!receivers.contains(entity.getManager()))
			messages.add(new OrderOutgoingMessage(entity.getManager(), new OrderMessage(entity.getOrderId(),
				RoleInOrder.MANAGER, entity.getOrderStatusCategory(), String.format(ApiResponseMessage.ORDER_CASHBACK_FOR_MANAGER,  entity.getCustomer()))));
		receivers.add(entity.getManager());
		if(!receivers.contains(entity.getRecommender()))
			messages.add(new OrderOutgoingMessage(entity.getRecommender(), new OrderMessage(entity.getOrderId(),
					RoleInOrder.RECOMMENDER, entity.getOrderStatusCategory(), String.format(ApiResponseMessage.ORDER_CASHBACK_FOR_RECOMMENDER,  entity.getCustomer()))));
		return messages;
	}

}
